/**
 * 案件设置
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($http,httpservice,$q,$cookies) {
    var caseBarDetailBarService = {};

    var userId = kbt.decrypt($cookies.get('cookieUserId'));
    /**
     * 归档案件
     * @param caseId
     */
    caseBarDetailBarService.setCaseArchive = function (caseId) {

        /*用户ID,案件ID*/
        var params = {"caseId":caseId};

        var deferred = $q.defer();
        $http({
            method: 'PUT',
            url: httpservice.setCaseArchiveUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /* 归档案件*/
  caseBarDetailBarService.setCaseUnArchive = function (caseId) {

    /*用户ID,案件ID*/
    var params = {"caseId":caseId};

    var deferred = $q.defer();
    $http({
      method: 'PUT',
      url: httpservice.setCaseUnArchiveUrl,
      data: params,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  };
    /**
     * 设置常用（案件置顶）
     * @param caseId
     * @param flag    0 取消置顶   1 置顶
     */
    caseBarDetailBarService.setCaseUsed = function (caseId,flag) {

        /*用户ID,案件ID*/
        var params = {"creatorId": userId,"caseId":caseId,"flag":flag};

        var deferred = $q.defer();
        $http({
            method: 'PUT',
            url: httpservice.setUsedUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 删除案件
     * @param caseId
     */
    caseBarDetailBarService.deleteCase = function (caseId,loginName) {

        /*用户ID,案件ID*/
        var params = {"lawyerId": userId, "caseId": caseId,"lawyerName":loginName};

        var deferred = $q.defer();
        $http({
            method: 'DELETE',
            url: httpservice.deleteCaseUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 退出案件
     * @param caseId
     */
    caseBarDetailBarService.exitCase = function (caseId,caseName) {

        /*用户ID,案件ID*/
        var params = {"lawyerId": userId, "caseId": caseId,"caseName":caseName};

        var deferred = $q.defer();
        $http({
            method: 'DELETE',
            url: httpservice.exitCaseUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    caseBarDetailBarService.changeNavName = function (name) {
        $('#changeNavName-id').text(name);
    };

    //案件基本信息设置
    caseBarDetailBarService.caseBaseSet = function (params) {
      return $http({
        method:"POST",
        url:httpservice.caseBaseSetUrl,
        params:params
      })
    };

    //角色设置
  caseBarDetailBarService.caseRoleSet = function (params) {
    return $http({
      method:"POST",
      url:httpservice.caseRoleSetUrl,
      params:params,
    })
  };

  //案件邀请律师
  caseBarDetailBarService.saveEmailLawyer = function (params) {
    return $http({
      method:"GET",
      url:httpservice.caseInvitedUrl,
      params:params,
    })
  };

  caseBarDetailBarService.caseGetMemberSingleUrl  = function (inviteInfo) {
    var deferred = $q.defer();
    $http({
      method: 'GET',
      url: httpservice.caseInviteSingleUrl,
      params: inviteInfo,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  };

  // 取得案件内律师
  caseBarDetailBarService.caseLawyersUrl  = function (params) {
    return $http({
      method:"GET",
      url:httpservice.taskCaseLawyersUrl,
      params:params,
    })
  };


    return caseBarDetailBarService;

};
